var express = require('express');
var router = express.Router();
var sql=require('./../sql')
var Homepic=require('./../sql/col/homepics')
/**
 * @api {get} api/homepic 获取首页大图
 * @apiDescription 获取首页大图
 * @apiName homepic
 * @apiSuccessExample { json } Success-Response:
 * {
 *  code: '200',
 *  message: '获取首页大图数据',
 *  data: []
 * }
 * {
 *  code: '100',
 *  message: '获取失败',
 *  err:err
 * }
 * @apiSampleRequest /api/homepic
 * @apiGroup homepic
 * @apiVersion 1.1.0
 **/
router.get('/', function(req, res, next) {
  sql.find(Homepic,{},{_id:0}).then(data=>{
    res.send({
      code: '200',
      message: '获取首页大图数据',
      data:data
    });
  }).catch((err)=>{
    res.send({
      code: '100',
      message: '获取失败',
      err:err
    })
  })
});

//  首页大图
router.get('/upload', function(req, res, next) {
  const arr=[{ homepicid: 'homepic_1', img: 'https://pic.flyco.net.cn/mall/cms/home/shaversBg.png', alt: '' }, 
  { homepicid: 'homepic_2', img: 'https://pic.flyco.net.cn/mall/cms/home/hairDrierBg.png?q=1', alt: '' }, 
  { homepicid: 'homepic_3', img: 'https://pic.flyco.net.cn/mall/cms/home/barberBg.png', alt: '' }, 
  { homepicid: 'homepic_4', img: 'https://pic.flyco.net.cn/mall/cms/home/hairironBg.png', alt: '' },
  { homepicid: 'homepic_5', img: 'https://pic.flyco.net.cn/mall/cms/home/socketBg.png', alt: '' },
  { homepicid: 'homepic_6', img: 'https://pic.flyco.net.cn/mall/cms/home/hairballBg.png', alt: '' }];
  sql.insert(Homepic,arr).then(()=>{
     res.send('上传成功');       
  })
  .catch(()=>{
    res.send('上传失败');
  })
});

module.exports = router;